<?php

namespace App\Models;

class Colleges extends Base
{

    protected $table = 'colleges';
    const STATUS_1 = 1;
    const STATUS_2 = 2;
    const STATUS_TEXT = [
        self::STATUS_1 => '<span class="el-tag">正常</span>',
        self::STATUS_2 => '<span class="el-tag el-tag--warning">锁定</span>',
    ];

    protected $fillable = [
        'id','thumb','title','catepid','cateid','file','status','content','view','download','created_at','updated_at'
    ];

    public function cate(){
        return $this->belongsTo('App\Models\Cates', 'cateid', 'id');
    }

    /**
     * 列表数据
     * @param array $fields
     * @param array $params
     * @param int $limit
     * @return mixed
     */
    protected function list($fields = ['*'], $params = [], $limit = 10){
        $lists = $this->select($fields)
            ->where(function ($query) use ($params) {
                $query ->where('status',self::STATUS_1);
                if($params['cateid']) $query ->where('cateid',$params['cateid']);
            })->with(['cate' => function ($query) {
                $query->select(['id','name'])->get();
            }])->orderBy('created_at','desc')
            ->paginate($limit);
        return $lists;
    }













}
